var e = require;
var t = module;
var o = exports;
var n,
    i = o,
    a =
        ((n = function (e, t) {
            return (n =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (e, t) {
                        e.__proto__ = t;
                    }) ||
                function (e, t) {
                    for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
                })(e, t);
        }),
        function (e, t) {
            function o() {
                this.constructor = e;
            }
            n(e, t), (e.prototype = null === t ? Object.create(t) : ((o.prototype = t.prototype), new o()));
        }),
    r = function (e, t, o, n) {
        var i,
            a = arguments.length,
            r = a < 3 ? t : null === n ? (n = Object.getOwnPropertyDescriptor(t, o)) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(e, t, o, n);
        else
            for (var s = e.length - 1; s >= 0; s--)
                (i = e[s]) && (r = (a < 3 ? i(r) : a > 3 ? i(t, o, r) : i(t, o)) || r);
        return a > 3 && r && Object.defineProperty(t, o, r), r;
    };
Object.defineProperty(i, "__esModule", {value: !0});
var s = e("BevNodeFactory"),
    c = e("PropCrlBevNode"),
    l = e("AvoidCrlBevNode"),
    d = e("WallCrlBevNode"),
    u = e("AttackCrlBevNode"),
    p = e("FoodCrlBevNode"),
    h = e("NoneCrlBevNode"),
    f = e("runPoisonCrlBevNode"),
    _ = e("GameData"),
    y = e("misssileCrlBevNode"),
    m = e("BaseControl"),
    g = cc._decorator,
    v = g.ccclass,
    w =
        (g.property,
        (function (e) {
            function t() {
                var t = (null !== e && e.apply(this, arguments)) || this;
                return (
                    (t._rootBevNode = null),
                    (t._missileBevNode = null),
                    (t.AIangle = 0),
                    (t.AI_Level_1 = !1),
                    (t.AI_Level_2 = !1),
                    (t.AI_Level_3 = !1),
                    t
                );
            }
            return (
                a(t, e),
                (t.prototype.init = function () {
                    e.prototype.init.call(this),
                        (this._rootBevNode = s.BevNodeFactory.oCreatePrioritySelectorNode(null, "root")),
                        s.BevNodeFactory.oCreateTeminalNode(
                            new f.default(this._rootBevNode, null),
                            this._rootBevNode,
                            "runPoisonCrlBevNode"
                        ),
                        s.BevNodeFactory.oCreateTeminalNode(
                            new d.default(this._rootBevNode, null),
                            this._rootBevNode,
                            "WallCrlBevNode"
                        );
                    var t = s.BevNodeFactory.oCreateNonePrioritySelectorNode(this._rootBevNode, "main");
                    s.BevNodeFactory.oCreateTeminalNode(new l.default(t, null), t, "AvoidCrlBevNode"),
                        s.BevNodeFactory.oCreateTeminalNode(new u.default(t, null), t, "AttackCrlBevNode"),
                        s.BevNodeFactory.oCreateTeminalNode(
                            new c.default(this._rootBevNode, null),
                            this._rootBevNode,
                            "PropCrlBevNode"
                        ),
                        s.BevNodeFactory.oCreateTeminalNode(
                            new p.default(this._rootBevNode, null),
                            this._rootBevNode,
                            "FoodCrlBevNode"
                        ),
                        s.BevNodeFactory.oCreateTeminalNode(
                            new h.default(this._rootBevNode, null),
                            this._rootBevNode,
                            "NoneCrlBevNode"
                        ),
                        (this._missileBevNode = s.BevNodeFactory.oCreatePrioritySelectorNode(null, "root2")),
                        s.BevNodeFactory.oCreateTeminalNode(
                            new y.default(this._missileBevNode, null),
                            this._missileBevNode,
                            "misssileCrlBevNode"
                        ),
                        this.startAI();
                }),
                (t.prototype.onDestroy = function () {
                    this.stopAI();
                }),
                (t.prototype.startAI = function () {
                    this.stopAI();
                    var e = 0.1;
                    if (_.default.instance.GameModel == _.GameModel.TimeLimit);
                    else {
                        var t = _.default.instance.SelfPlayerData.fraction;
                        t < 3e3
                            ? (e = 0.2)
                            : t >= 3e3 && t < 3e4
                            ? (e = 0.1)
                            : t >= 3e4 && t < 8e4
                            ? (e = 0.05)
                            : t >= 8e4 && (e = 0.02);
                    }
                    this.schedule(this.onTick, e);
                }),
                (t.prototype.stopAI = function () {
                    this.unschedule(this.onTick);
                }),
                (t.prototype.onTick = function (e) {
                    if (!this._snake.isDie && this._snake.node.active) {
                        var t = {snake: this._snake, _dt: e},
                            o = {};
                        this._rootBevNode.Evaluate(t) &&
                            (this._rootBevNode.Tick(t, o),
                            this.onSnakeAccelerate(o.speed),
                            o.vector &&
                                (this._snake.porp_shield_index >= 10 && this.useShield(),
                                this.onSnakeMoving(o.vector))),
                            _.default.instance.GameModel == _.GameModel.eatChicken &&
                                this._missileBevNode.Evaluate(t) &&
                                (this._missileBevNode.Tick(t, o), o.isMissile && this.useMissile());
                        var n = _.default.instance.SelfPlayerData.fraction;
                        n < 3e4 && n >= 3e3 && !this.AI_Level_1
                            ? ((this.AI_Level_1 = !0), this.startAI())
                            : n >= 3e4 && n < 8e4 && !this.AI_Level_2
                            ? ((this.AI_Level_2 = !0), this.startAI())
                            : n >= 8e4 && !this.AI_Level_3 && ((this.AI_Level_3 = !0), this.startAI());
                    }
                }),
                (t.prototype.covertToAngle = function (e) {
                    var t = Math.atan2(e.y, e.x);
                    return cc.misc.radiansToDegrees(t);
                }),
                r([v], t)
            );
        })(m.default));
i.default = w;
